using System;
using UnityEngine;
using UnityEngine.UI;

namespace Voodoo.Utils
{
	public class CountDown : MonoBehaviour
	{
		private Text _timer;

		private void Awake()
		{
			_timer = GetComponentInChildren<Text>();
		}

		private void Start()
		{
			DelayAction obj = (DelayAction)((Action)delegate
			{
				DisplayTimer("TIME'S UP");
			}).Delay(10f).SkipIf(() => Input.GetMouseButtonDown(0)).Frequency(1f)
				.Timescale(TimeScale.Scaled)
				.Begin();
			obj.OnDelaySkipped = (Action)Delegate.Combine(obj.OnDelaySkipped, (Action)delegate
			{
				ColorTimer(Color.yellow);
			});
			obj.OnDelayRunning = (Action<float>)Delegate.Combine(obj.OnDelayRunning, new Action<float>(DisplayTimer));
		}

		private void DisplayTimer(float time)
		{
			_timer.text = time.ToString("F0") + "\ntap to skip";
		}

		private void DisplayTimer(string text)
		{
			_timer.text = text;
		}

		private void ColorTimer(Color color)
		{
			_timer.color = color;
		}
	}
}
